#!/usr/local/bin/python3
# -*- coding: UTF-8 -*-
"""
@author:apple
@file:demo01.py
@time:2021/07/21
"""
# import sys
import time


def timer(func):
    def inner(*args, **kwargs):
        ...
        start = time.time()
        func(*args, **kwargs)
        print("耗时:{}".format(time.time() - start))

    return inner


def router(path, method='GET'):
    ...
    def outer(func):
        ...
        def innner(*args, **kwargs):
            ...
            retVal = func(*args, **kwargs)
            return retVal
        return innner

    return outer

r_x = 10
r_y = 20

# @timer
@router('/')
def run(name):
    ...
    global r_x,r_y

    time.sleep(1)
    print(name)
    return 1,2


def test02():
    ...
    import module01
    import module02
    print(module01.m_x)
    module01.m_x = 90
    module02.run()
    print(module01.m_x)
    print(id(module01))


def test03():
    ...
    # import demo01
    import sys
    # demo01_m = sys.modules['demo01']
    # print(demo01.r_x)
    # demo01_m.r_x = 30
    globals()['r_x'] = 30

    # print(demo01.r_x)
    # print(id(demo01))



def test04():
    ...
    methods = []
    for i in range(5):
        methods.append(lambda x,i=i:i*x)

    print(methods[0](3))


if __name__ == '__main__':
    pass
    # ret = run('哈哈')
    # print(ret)
    # test03()
    # # test03()
    # print(r_x)
    test04()
